package cn.vconinfo.app.exception;


import cn.vconinfo.app.enums.BusinessService;

/**
 * @author vconinfo
 * @creaetdOn 11:34 2019/8/11
 * @description:
 */
public class HandleBusinessException extends RuntimeException {
    private String msg;
    private int code;
    private String subCode;

    public HandleBusinessException(String msg) {
        super(msg);
        this.msg = msg;
    }

    public HandleBusinessException(String msg, Throwable t) {
        super(msg, t);
        this.msg = msg;
    }

    public HandleBusinessException(BusinessService.CommonBusinessCode commonBusinessCode) {
        super(commonBusinessCode.getMsg());
        this.code = commonBusinessCode.getCode();
        this.subCode = commonBusinessCode.getCodeStr();
        this.msg = commonBusinessCode.getMsg();
    }

    /**
     * 附加信息 前置
     * @param commonBusinessCode
     * @param extra 附加消息
     */
    public HandleBusinessException(BusinessService.CommonBusinessCode commonBusinessCode, String extra) {
        super(commonBusinessCode.getMsg());
        this.code = commonBusinessCode.getCode();
        this.subCode = commonBusinessCode.getCodeStr();
        this.msg = extra + commonBusinessCode.getMsg();
    }

    /**
     * 附加信息，后置
     * @param commonBusinessCode
     * @param extra
     */
    public HandleBusinessException(String extra, BusinessService.CommonBusinessCode commonBusinessCode) {
        super(commonBusinessCode.getMsg());
        this.code = commonBusinessCode.getCode();
        this.subCode = commonBusinessCode.getCodeStr();
        this.msg =  commonBusinessCode.getMsg() + extra;
    }

    /**
     * 附加信息，前后置
     * @param commonBusinessCode
     * @param extra
     */
    public HandleBusinessException(String extra, BusinessService.CommonBusinessCode commonBusinessCode, String end) {
        super(commonBusinessCode.getMsg());
        this.code = commonBusinessCode.getCode();
        this.subCode = commonBusinessCode.getCodeStr();
        this.msg =  extra + commonBusinessCode.getMsg() + end;
    }

    public HandleBusinessException(BusinessService.CommonBusinessCode commonBusinessCode, Throwable t) {
        super(commonBusinessCode.getMsg(), t);
        this.code = commonBusinessCode.getCode();
        this.subCode = commonBusinessCode.getCodeStr();
        this.msg = commonBusinessCode.getMsg();
    }


    public HandleBusinessException(int code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public HandleBusinessException(int code, String msg, Throwable t) {
        super(msg, t);
        this.code = code;
        this.msg = msg;
    }

    public HandleBusinessException(int code, String subCode, String msg) {
        super(msg);
        this.code = code;
        this.subCode = subCode;
        this.msg = msg;
    }

    public HandleBusinessException(int code, String subCode, String msg, Throwable t) {
        super(msg, t);
        this.code = code;
        this.subCode = subCode;
        this.msg = msg;
    }
    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getSubCode() {
        return subCode;
    }

    public void setSubCode(String subCode) {
        this.subCode = subCode;
    }

    @Override
    public String toString() {
        return "HandleBusinessException{" +
                "msg='" + msg + '\'' +
                ", code=" + code +
                ", subCode='" + subCode + '\'' +
                '}';
    }
}
